package com.yanqu.road.server.cmd.activity.stronghold.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_CROSS_STRONGHOLD_WILD_OPEN_BOX, desc = "开启宝箱返回")
public class CrossStrongholdOpenBoxResultCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossStrongholdOpenBoxRespMsg msg = StrongholdWarProto.CrossStrongholdOpenBoxRespMsg.parseFrom(packet.getBytes());
        ret = msg.getRet();
        if (ret == 0) {
            String reward = msg.getReward();
            Property property = PropertyHelper.parseStringToProperty(reward);
            player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.Stronghold, eLogMoneyType.StrongholdOpenBox);
        }
        player.sendPacket(ClientProtocol.U_STRONGHOLD_WAR_OPEN_BOX,msg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
